//
//  ArticleBigImageShowView.m
//  Yanwei
//
//  Created by Seven-Augus on 2017/6/19.
//  Copyright © 2017年 DCloud. All rights reserved.
//

#define kStatusImageWidth 80
#define kStatusImageHeight 80
#define kStatusImageMargin 5

#import "ArticleBigImageShowView.h"

@interface ArticleBigImageShowView ()

@end

@implementation ArticleBigImageShowView

- (instancetype)initWithFrame:(CGRect)frame bigImgUrlsArray:(NSMutableArray *)bigImgUrlsArray bigImgIndex:(NSInteger)bigImgIndex {
    self = [super initWithFrame:frame];
    if (self) {
        if (frame.size.width == 0) {
            self.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64);
        }
        self.bigImgUrlsArray = bigImgUrlsArray;
        self.bigImgIndex = bigImgIndex;
        
        // 创建子视图
        [self tapViewWithPhotos:
         [self createPhotosWithImagesArray:bigImgUrlsArray]
         ];
    }
    return self;
}

- (NSArray *)createPhotosWithImagesArray:(NSArray *)imagesArray {
    NSMutableArray *photos = [NSMutableArray array];
    
    for (int i = 0; i < imagesArray.count; i++) {
        // 1.创建imageView
        UIImageView *child = [[UIImageView alloc] init];
        child.userInteractionEnabled = YES;
        child.clipsToBounds = YES;
        child.contentMode = UIViewContentModeScaleToFill;
        
        JLPhoto *photo = [[JLPhoto alloc] init];
        // 1.1设置原始imageView
        photo.sourceImageView = child;
        // 1.2设置大图URL
        photo.bigImgUrl = imagesArray[i];
        // 1.3设置图片tag
        photo.tag = i;
        [photos addObject:photo];
    }
    return photos;
}


/**
 创建图片浏览器
 */
- (JLPhotoBrowser *)createBrowser {
    return [JLPhotoBrowser photoBrowser];
}

#pragma mark - tap
- (void)tapViewWithPhotos:(NSArray *)photos {
    // 创建图片浏览器
    self.photoBrowser = [self createBrowser];
    // 设置JLPhoto数组
    self.photoBrowser.photos = photos;
    // 设置当前要显示图片的tag
    self.photoBrowser.currentIndex = (int)_bigImgIndex;
    // 显示图片浏览器
    [self.photoBrowser show];
    __weakConfigure
    self.photoBrowser.JLPhotoBlock = ^(NSInteger index) {
        NSLog(@"您点击了第%@张图片", @(index));
        [__weakSelf removeFromSuperview];
    };
}

@end
